/**
 * @author Songlin
 */
var QS_watchlistImportor=null;
var wachlistImport = function(cfg, callBack){
	var qslan=QS_Lang.watchlist;
	this.container = null;
	this.el = null;
	this.cfg = {
		isToExistWatchList: false,
		portfolioId: null,
		type: 0,
		importType: "import_manual",
		dl: 0,
		maxTicker:200
	};
	
	$.extend(this.cfg, cfg);
	this.callBack = callBack;
	
	this.type = "create";
	this.HTML = '<div class="qs-manualimport">' +
		'<div class="hd clearfix">' +
			'<div class="mhd"><a class="impl">'+qslan["copyprompt"]+'</a><a href="javascript:void(0)" class="example"> </a> </div>' +
			'<div class="ehd hidden"><a class="impl2">'+qslan["uploadprompt"]+'</a><a href="javascript:void(0)" class="example"> </a> </div>' +
		'</div>' +
		'<div class="bd"><div class="tabpanel"><textarea></textarea></div></div>' +
		'<div class="impgrid hidden"><div class="headerpanel clearfix"></div><div class="gridpanel"></div></div>' +
		'<div class="ebd hidden">' +
			'<form name="excel-import" class="excelImportForm" action="testImportExcel2.jsp" method="post" enctype="multipart/form-data" target="hideIframe">' +
				'<div class="ifile">' +
					'<div>'+qslan["oversizeprompt"]+'</div>' +
					'<input name="x" class="file" type="file" size="33">' +
				'</div>' +
				'<iframe name="hideIframe" style="display:none;"></iframe>' +
			'</form>' +
		'</div>' +
		'<div class="ft">' +
			'<a href="javascript:void(0)" class="qs-ui-btn qs-import-back hidden">'+qslan["back"]+'</a>' +
			'<a href="javascript:void(0)" class="qs-ui-btn qs-import-next">'+qslan["next"]+'</a>' +
			'<a href="javascript:void(0)" class="qs-ui-btn qs-import-import hidden">'+qslan["import"]+'</a>' +
			'<a href="javascript:void(0)" class="qs-ui-btn qs-import-cancel">'+qslan["cancel"]+'</a>' +			
		'</div>' +
	'</div>';
	
	this.textarea = null;
	this.tabpanel = null;
	this.txt = null;
	this.tickers = [];
	this.validTickers = [];
	//this.wlObj = null;
	this.win = null;
	this.gridHeaderContent=[{txt: qslan["select"],val: ""}, {txt: qslan["symbol"],val: "Symbol"}, 
			{txt: qslan["numofshares"],val: "Quantity"}, {txt: qslan["purchasedate"],val: "Date"}, 
			{txt: qslan["purchaseprice"],val: 'PurchasePrice'}, {txt: qslan["commission"],val: 'Comm'}];
	this.headerList = [];
	this.dataGrid = [];
	this.gridCallbacks = null;
	
	this.tValidation = new tickerValidation(101);
	this.init();
};

wachlistImport.prototype = {
	init: function(){
		var self = this;
		this.win = new Util.RtqWindow(document.body, {
			windowReady: function(obj){
				self.container = obj.contentEl;
				self.el = $(self.HTML);
				self.textarea = self.el.find(".bd textarea")[0];
				self.el.appendTo(self.container);
				self._bindEvent();
				
				obj.loadingEl = $('<div class="x-tool x-tool-loading" title="Loading"><img src="'+(QS_Theme=="black"?"theme/black/loading.gif":"IM/loading.gif")+'" /> Loading...</div>').appendTo(obj.el.find('div.win-hd'));
		        obj.showLoading = function(){
					obj.titleEl.find('h3').hide();
		            obj.loadingEl.width(obj.cfg.width-obj.operatorEl.width());
		            obj.loadingEl.show();           
		            if(obj.settingPanelObj){
		                obj.settingPanelObj.setDisabled();
		            }
					obj.el.addClass('rtq-win-onloading');
					obj.contentMask.show();
		        };
		        obj.hideLoading = function(){
					obj.titleEl.find('h3').show();
		            obj.loadingEl.hide();
		            if(obj.settingPanelObj){
		                obj.settingPanelObj.setEnabled();
		            }
					obj.el.removeClass('rtq-win-onloading'); 
		            obj.contentMask.hide();
		        };
			},
			beforeClosed: function(){
				self.close();
			},
			onResized: function(){
				self.reSize();
			}
		}, {
			title: QS_Lang.watchlist["title"],
			width: 350,
			minWidth: 350,
			height: 285,
			minHeight: 285,
			resizable: true,
			isGlobal: true,
			hasSettingPanel: false,
			closeAction: 'hide'
		});		
		
		rtqWindowGroup.register(this.win);
		this.win.contentMask=$('<div class="rtq-win-bd-mask" style="height:259px;"></div>').appendTo(this.win.el);
		this.win.hide();
	},
	_bindEvent: function(){
		var self = this;
		this.el.find(".qs-import-cancel").bind("click.manualimport", function(){
			self.close();
		});
		this.el.find(".example").bind("click.manualimport", function(){
			workspaceManager.openOnlineSupportDialog("support.jsp?mtd=import&theme="+QS_Theme+"&userId="+QS_UserID+"&userEmail="+QS_UserNAME);
			/**var d = self._formatHoldingDate(new Date());
			self.textarea.value = "IBM\t148.57\t100\t" + d + "\t0.20\n" +
							"GOOG\t616.69\t100\t" + d + "\t0.02\n" +
							"MSFT\t28.19\t100\t" + d + "\t0.10\n" +
							"SINA\t85.53\t100\t" + d + "\t0.05\n" +
							"BIDU\t106.25\t100\t" + d + "\t0.08";
							*/
		});
		this.el.find(".qs-import-next").bind("click.manualimport", function(){
			if (self.cfg.importType == 'import_manual') {
				if ($.trim(self.textarea.value) == '') {
					Util.alert(QS_Lang.text["wlimportcopyprompt"]);
					return;
				}
				self.parse(self.textarea.value);
			}
			else {
				self.cfg.dFile = self.el.find("input[name='x']").first();
				self.cfg.dForm = self.el.find("form[name='excel-import']")[0];
				if ($.trim(self.cfg.dFile.val()) == '') {
					Util.alert(QS_Lang.text["wlimportinputfile"]);
					return;
				}
				self.win.showLoading();
				self.cfg.dForm.submit();
			}
		});
		this.el.find(".qs-import-import").bind("click.manualimport", function(){
			if (!self.checkColumn()) 
				return;
			self.win.showLoading();
			self.dealWithImport();
		});
		this.el.find(".qs-import-back").bind("click.manualimport", function(){
			self.toggle(self.cfg.importType);
		});
	},
	__getWidthByIdx: function(l,num){
		var f = function(l, i, w){
			if (i == l - 1) {
				return w - Math.ceil(w / l) * (l - 1);
			}
			return Math.ceil(w / l);
		}
		var a = [];
		for (var i = 0; i < l; i++) {
			a.push(f(l, i, num));
		}
		a = a.sort();
		while (a[0] < Math.floor(num / l) || a[l - 1] > Math.ceil(num / l)) {
			a[0]++;
			a[l - 1]--;
			a = a.sort();
		}
		return a;
	},
	parse: function(inputText){
		if(this.cfg.importType == 'excel'){
			this.win.hideLoading();
			if ($.trim(inputText).length === 0) {
				Util.alert(QS_Lang.text["wlimportemptyfile"]);
			}
		}
		if (inputText.length > 0) {
			inputText = inputText.replace(/[ \f\n\r\v]{1,}$/gi,"\n");
			CSVParser.resetLog();
			var parseOutput = CSVParser.parse(inputText, false);
			this.dataGrid = parseOutput.dataGrid;
			var headerNames = parseOutput.headerNames;
			var headerTypes = parseOutput.headerTypes;
			var errors = parseOutput.errors;
			if (errors != "") {
				Util.alert(errors);
				return;
			}
			if(headerNames.length>10){
				Util.alert(QS_Lang.text["wlimportcolumnlimit"]);
				return;
			}
			this.toggle("grid");
			var column = [{
				header: "rowid",
				dataIndex: 'rowid',
				width: 0,
				dataType: 'string',
				hide: true
			}], data = [];
			
			if (headerNames && headerTypes && headerNames.length == headerTypes.length) {
				var l = headerNames.length;
				var w = this.__getWidthByIdx(l, 95);
				for (var i = 0; i < l; i++) {
					column.push({
						header: headerNames[i],
						dataIndex: headerNames[i],
						width: w[i]+"%",
						dataType: headerTypes[i]
					});
				}
			};
			
			for (var i = 0; i < this.dataGrid.length; i++) {
				var d = {
					rowid: i+1
				};
				if (this.dataGrid[i].length == headerNames.length) 
					for (var idx = 0; idx < headerNames.length; idx++) {
						if (typeof(this.dataGrid[i][idx]) != 'undefined') 
							d[headerNames[idx]] = this.dataGrid[i][idx];
					}
				data.push(d);
			};
			
			
			this.buildGrid(headerTypes.length, column, data);
			
		}//end test for existence of input text	
	},
	buildHeaderList:function(cols){
		var container = this.el.find(".impgrid .headerpanel");
		var self = this;
		window.setTimeout(function(){
			var hasScroll = self.grid.scrollPanel.scrollbarY.isShow;
			if (hasScroll) {
				container.css({
					"margin-right": "11px"
				});
			}
		},200);
		var w = this.__getWidthByIdx(cols, 95);
		for (var i = 0; i < cols; i++) {
			var html = $('<div class="headerCell" style="width:' + (i==cols-1?(w[i]+4):w[i]) + '%"></div>');
			html.appendTo(container);
			var header = new Util.DropDownList(html, function(t, v){
				for (var x = 0; x < self.headerList.length; x++) {
					if (v != "" && v == self.headerList[x].getValue() && self.headerList[x] != this) {
						Util.alert(QS_Lang.text["wlimportduplicate"]);
						this.selectItemByIndex(0);
						return;
					}
				}
			}, this.gridHeaderContent, {
				width: html.width()-2
			});
			this.headerList.push(header);
		}
	},
	buildGrid: function(cols, column, data){
		if (!this.gridCols || cols != this.gridCols) {
			this.clearGrid();
			this.gridCols = cols;
			this.headerList = [];
			var h = this.win.cfg.height;
			column.push({
				header: "",
				dataIndex: 'remove',
				width: "4%",
				type: 'remove',
				renderer: '<a href="javascript:;">Remove</a>'
			});
			
			var self = this;
			var cb = {
				onRowRemove: function(id, row){
					self.deleteRow(id, row);
				}
			}
			this.grid = new Util.DataGrid(this.el.find(".impgrid .gridpanel"), [], {
				column: column,
				autoWidth: true,
				height: (h - 104),
				autoWidth: true,
				headerRow: false,
				htmlLayer: 'div',
				rowDragable: true,
				rowDropable: true,
				rowDragDropGroup: 'GRID1'
			}, cb);
			this.grid.reBindData(data);
			this.buildHeaderList(cols);
		}
		else {
			this.grid.reBindData(data);
		}
	},
	deleteRow: function(id, row){
		if (!this.gridDataMap) {
			this.gridDataMap = {};
			for (var idx in this.grid.data) {
				this.gridDataMap[idx] = this.grid.data[idx]["rowid"];
			}
		}
		var idx = 0 ;
		for (var o in this.gridDataMap) {
			if (this.gridDataMap[o] >= id) {
				if (this.gridDataMap[o] == id) {
					idx = o;
				}
				this.gridDataMap[o] = this.gridDataMap[parseInt(o) + 1];
			}
		}
		this.dataGrid.splice(idx, 1);
	},
	checkColumn: function(){
		if (this.dataGrid.length == 0) {
		  Util.alert(QS_Lang.text["wlimportnoticker"]);
		  return false;
		}
		this.columnMap = {};
		for (var i = 0; i < this.headerList.length; i++) {
			this.columnMap[this.headerList[i].getValue()] = i;
		}
		if (!this.columnMap.hasOwnProperty("Symbol")) {
			Util.alert(QS_Lang.text["wlimportnosymbolcolumn"]);
			return false;
		}
		
		var dValidformat1 = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
		var dValidformat2 = /^\d{1,2}\-\d{1,2}\-\d{4}$/;
		var dtCh=/\//,qslang=QS_Lang.watchlist;
		for (var i = 0; i < this.dataGrid.length; i++) {
			for (var o in this.columnMap) {
				var val = this.dataGrid[i][this.columnMap[o]];
				switch (o) {
					case "Quantity":
						if(typeof(val)=="undefined"||""==val){
							this.dataGrid[i][this.columnMap[o]]='1.00';
						}else if(!/^[+]?\d+(\.\d+)?$/.test(val)){
							Util.alert(String.format(QS_Lang.watchlist["import_prompt"], qslang["numofshares"],i + 1));
							return false;
						}
						break;
					case "PurchasePrice":
						if(typeof(val)=="undefined"||""==val){
							this.dataGrid[i][this.columnMap[o]]='1.00';
						}else if(!/^[+]?\d+(\.\d+)?$/.test(val)){
							Util.alert(String.format(QS_Lang.watchlist["import_prompt"], qslang["purchaseprice"],i + 1));
							return false;
						}
						break;
					case "Comm":						
						if(typeof(val)=="undefined"||""==val){
							this.dataGrid[i][this.columnMap[o]]='0';
						}else if(!/^[+]?\d+(\.\d+)?$/.test(val)){
							Util.alert(String.format(QS_Lang.watchlist["import_prompt"], qslang["commission"],i + 1));
							return false;
						}
						break;
					case "Date":
						var val = this.dataGrid[i][this.columnMap[o]];
						if (typeof(val) == "undefined" || "" == val) {
							this.dataGrid[i][this.columnMap[o]] = this._formatHoldingDate(new Date());
						} else {						
							if (val.indexOf("-") != -1) {
								dtCh = /\-/;
							}
							else {
								dtCh = /\//;//purchasedate  MM/DD/YYYY or MM-DD-YYYY
							}
							if (!dValidformat1.test(val) && !dValidformat2.test(val)) {
								Util.alert(String.format(QS_Lang.watchlist["import_formatprompt"], qslang["purchasedate"],"MM/DD/YYYY or MM-DD-YYYY",i + 1));
								return false;
							}
							
							var dFields = val.split(dtCh);//import_datarangeprompt
							var d = new Date(dFields[2], parseInt(dFields[0],10) - 1, dFields[1]);
							if ((d.getMonth() + 1 != parseInt(dFields[0],10)) || (d.getDate() != parseInt(dFields[1],10)) || (d.getFullYear() != parseInt(dFields[2],10))) {
								Util.alert(String.format(QS_Lang.watchlist["import_datarangeprompt"], qslang["purchasedate"],i + 1));
							}
							this.dataGrid[i][this.columnMap[o]] = this._formatHoldingDate(d);
						}						
						break;
				}
			}
		}
		return true;
	},
	dealWithImport: function(){
		var idx = 0;
		for (var i = 0; i < this.headerList.length; i++) {
			if (this.headerList[i].getValue() == "Symbol") {
				idx = i;
				break;
			}
		}
		this.tickers = [];
		for (var i = 0; i < this.dataGrid.length; i++) {
			this.tickers.push($.trim(this.dataGrid[i][idx]));
		}
		
		this.validate();
	},
	validate: function(){
		if (this.tickers.length == 0) {
			Util.alert(QS_Lang.text["wlimportnotickerinput"]);
			return;
		}
		var self = this;
		this.tValidation.showAlert = false;
		this.tValidation.checkTickers(this.tickers, function(validTickers){
			self.validTickers = validTickers;
			self.analyse();
		});
	},
	_formatHoldingDate: function(d){
		var year = d.getFullYear();
		var month = d.getMonth() + 1;
		month = month < 10 ? ('0' + month) : month;
		var day = d.getDate();
		day = day < 10 ? ('0' + day) : day;
		return (month + '-' + day + '-' + year);
	},
	analyse: function(){
		if (this.validTickers.length == 0) {
			this.win.hideLoading();
			Util.alert(QS_Lang.text["wlimporttickerinvalid"]);
			return;
		}
		var isCom = QSPC.moduleConfigs[0].isDotComUser;
		if (this.validTickers.length > 0) {
			var lst = [], dstr = this._formatHoldingDate(new Date());
			for(var i=0;i<this.tickers.length; i++){
				for (var j = 0; j < this.validTickers.length; j++) {
					if ($.trim(gData[this.validTickers[j]].performanceId || gData[this.validTickers[j]].secId) == "") {
						this.validTickers.splice(j--, 1);
						continue;
					}
					
					if (this.tickers[i].toUpperCase() == gData[this.validTickers[j]]["performanceId"] ||
						this.tickers[i].toUpperCase() == gData[this.validTickers[j]]["secId"] ||
						this.tickers[i].toUpperCase() == gData[this.validTickers[j]]["ticker"] ||
						this.tickers[i].toUpperCase() == gData[this.validTickers[j]]["tenforeTicker"] ||
						this.tickers[i].toUpperCase() == (gData[this.validTickers[j]]["exch"] + ":" + gData[this.validTickers[j]]["ticker"])) {
						
						var d = {
							"Name": gData[this.validTickers[j]].Name || "",
							"Action": "1",
							"PurchasePrice": gData[this.validTickers[j]].LastPrice || "1.00",
							"Quantity": "1.00",
							"Ticker": gData[this.validTickers[j]].ticker,
							"SecId": (gData[this.validTickers[j]].performanceId || gData[this.validTickers[j]].secId),
							"Country": gData[this.validTickers[j]].country,
							"Date": dstr,
							"Comm": "0"
						};						
						
						for (var o in this.columnMap) {
							if (o != 'Symbol' && o != '') {
								d[o] = this.dataGrid[i][this.columnMap[o]];
							}
						}
						lst.push(d);
						break;
					}
				}
			}
			this.saveToWatchlist(lst,false);
		}
	},
	saveToWatchlist: function(lst,validated){
		if(!validated){
			this.win.hideLoading();
			if (lst.length == 0) {
				Util.alert(QS_Lang.text["wlimporttickerinvalid"]);
				return;
			}
			
			var msg = this.msg();
			if (msg != '') {
				var self = this;
				Util.confirm(msg+" " + QS_Lang.watchlist["continueprompt"], function(b){
					if (b) {
						self.saveToWatchlist(lst, true);
						/**var len = QS_watchlistDataManager.getMaxTickers();
						if (self.cfg.type == 1) {
							QS_watchlistDataManager.getHoldings(self.cfg.portfolioId, function(holdings){
								if (lst.length > (len - holdings.length)) {
									Util.alert("Watchlist has reached the tickers number limit(" + len + "), Please reduce your tickers number.");
									return;
								}
								self.saveToWatchlist(lst, true);
							});
							
						}
						else {
							if (lst.length > (len - 0)) {
								Util.alert("Watchlist has reached the tickers number limit(" + len + "), Please reduce your tickers number.");
								return;
							}
							self.saveToWatchlist(lst, true);
						}*/
					}
				});
				return;
			}
		}
		
		this.win.showLoading();	
		var toExist = this.cfg.isToExistWatchList;
		if (lst.length > (this.cfg.maxTicker - (toExist ? this.cfg.currentLen : 0))) {
			this.win.hideLoading();	
			Util.alert(String.format(QS_Lang.text["wlimporttickerovermax"],this.cfg.maxTicker));
			return;
		}
		
		if(!toExist){
			this.__newWatchList(lst);
		}else{
			this.callBack.invokeCallBackByName('onImportToCurrentList',[lst, this.cfg.portfolioId]);
			this.win.hideLoading();
			this.close();
		}
	},
	__newWatchList: function(list){
		var self = this;
		Util.prompt(QS_Lang.text["watchlistinput"], function(name){
			if (!name || typeof(name) == 'undefined') {
				self.__newWatchList(list);
				return;
			}
			if ($.trim(name) == '') {
				Util.message(QS_Lang.text["watchlistinput"]);
				self.__newWatchList(list);
				return;
			}
			if (!QS_Validator.test(name, 'name')) {
				self.__newWatchList(list);
				return;
			}
			if (QS_watchlistDataManager.checkWatchlistName(name) !== false) {
				Util.message(QS_Lang.text["watchlisttitle2"]);
				self.__newWatchList(list);
				return;
			}
			
			self.callBack.invokeCallBackByName('onImportToNewList',[list, name]);
			self.win.hideLoading();
			self.close();
		}, {
			"cancelCallBack": function(){
				self.win.hideLoading();
			}
		});
	},
	/**
	_save2NewWatchList: function(list, name){
		var self = this;
		if (!name || typeof(name) == 'undefined') {
			this.__newWatchList(list);
			return;
		}
		
		if ($.trim(name) == '') {
			Util.message(QS_Lang.text["watchlistinput"]);
			this.__newWatchList(list);
			return;
		}
		
		if (!QS_Validator.test(name, 'name')) {
			this.__newWatchList(list);
			return;
		}
		
		if (QS_watchlistDataManager.checkWatchlistName(name) !== false) {
			Util.message(QS_Lang.text["watchlisttitle2"]);
			this.__newWatchList(list);
			return;
		}
		
		
		QS_watchlistDataManager.createWatchList(name, QSPC.moduleConfigs[0].isDotComUser?'1':'0', list, function(args){
			var pid = args["portfolioId"];
			QS_watchlistDataManager.saveHoldings(pid,null);
			if (typeof(self.wlObj.openPortfolio)=='function') {
				self.wlObj.openPortfolio(pid, '', null, true);
				self.wlObj.startupObj.refreshList();
			}
			self.close();
		});
		this.win.hideLoading();
	},
	_saveToExistWatchlist: function(lst){
		QS_watchlistDataManager.insertHoldings(this.cfg.portfolioId, lst, true);
		QS_watchlistDataManager.saveHoldings(this.cfg.portfolioId,null);
		if (QS_watchlistDataManager.getPermissionById(this.cfg.portfolioId) == 0) {
			this.wlObj.refreshGrid(true);
		}
		this.close();
		this.win.hideLoading();
	},*/
	msg: function(){
		//=====================================================invalid
		var inValidTickers = "", iVolume = 0,rtnStr="";
		for (var i = 0; i < this.tickers.length; i++) {
			if($.trim(this.tickers[i])=="")continue;
			var d=false;
			for (var j = 0; j < this.validTickers.length; j++) {
				if(this.tickers[i].toUpperCase() == gData[this.validTickers[j]]["performanceId"]
						 ||this.tickers[i].toUpperCase()  == gData[this.validTickers[j]]["secId"]
						 ||this.tickers[i].toUpperCase() == gData[this.validTickers[j]]["ticker"]
						 ||this.tickers[i].toUpperCase() == gData[this.validTickers[j]]["tenforeTicker"]
						 ||this.tickers[i].toUpperCase() == (gData[this.validTickers[j]]["exch"]+":"+gData[this.validTickers[j]]["ticker"])){
					d=true;
					break;
				}
			}
			
			if(!d){
				inValidTickers+=this.tickers[i]+", "; 
				iVolume++;
			}
		}
		
		if (inValidTickers != "") {
			inValidTickers = inValidTickers.substr(0, inValidTickers.length - 2);
			if(iVolume>0){
				rtnStr=(iVolume+(iVolume > 1?" tickers(":" ticker(")+inValidTickers+") invalid,");
			}
		}
		return rtnStr;
	},
	close: function(){
		if (this.el.find(".bd").hasClass("hidden")) {
			this.toggle("import_manual");
		}
		this.win.hideLoading();
		this.clearData();
		this.win.hide();
	},
	open: function(type, cfg){//type, cfg
		this.cfg.importType = type;
		if (type == "import_manual" || type == "excel") {
			this.win.setTitle(type == "import_manual" ? "Copy & Paste" : "Upload");
		}
		
		if (!cfg.inCurrentList) {
			this.cfg.isToExistWatchList = false;
			this.cfg.type = 0;
			this.cfg.dl = 0;
		}
		else {
			this.cfg.isToExistWatchList = true;
			this.cfg.currentLen = cfg.currentLen;
			this.cfg.portfolioId = cfg.portfolioId;
			this.cfg.type = 1;
		}
		
		//this.cfg.maxTicker = maxTicker;
		//this.wlObj = obj;
		this.toggle(type);
		this.win.show();
		this.reSize();		
	},
	toggle: function(type){
		var classMap = {
			"import_manual": [".mhd", ".bd", ".qs-import-next"],
			"excel": [".ehd", ".ebd", ".qs-import-next"],
			"grid": [".impgrid", ".qs-import-back", ".qs-import-import"]
		}
		for (var t in classMap) {
			for (var idx = 0, len = classMap[t].length; idx < len; idx++) {
				var selector = classMap[t][idx];
				if (t != type) {
					if ((type == "grid" && (selector == ".mhd" || selector == ".ehd")) ||
					(type != "grid" && selector == ".qs-import-next")) {
					}
					else {
						this.el.find(classMap[t][idx]).addClass("hidden");
					}
				}
				else {
					this.el.find(classMap[t][idx]).removeClass("hidden");
				}
			}
		}
	},
	clearData: function(){
		this.tickers = [];
		this.cfg.isToExistWatchList = false;
		this.cfg.portfolioId = null;
		this.cfg.type = 0;
		this.txt = null;
		this.textarea.value = "";
		this.clearGrid();
	},
	clearGrid: function(){
		this.grid = null;
		this.gridCols = null;
		this.headerList = null;
		this.el.find(".impgrid .headerpanel").html('');
		this.el.find(".impgrid .gridpanel").html('');
	},
	reSize: function(){
		var h = this.win.cfg.height;
		var w = this.win.cfg.width;
		this.el.find(".bd").height(h - 85);
		this.el.find(".ebd").height(h - 93);
		this.el.find(".bd .tabpanel").height(h - 85);
		this.el.find(".bd .tabpanel textarea").height(h - 85);
		this.el.find(".bd .tabpanel textarea").width(w);
		this.el.find(".impgrid .gridpanel").height(h - 104);
		if (this.grid) {
			this.grid.resize('100%', h - 104);
			var self = this;
			window.setTimeout(function(){
				if (self.grid.scrollPanel.scrollbarY.isShow) {
					self.el.find(".impgrid .headerpanel").css({
						"margin-right": "11px"
					});
				}
				else {
					self.el.find(".impgrid .headerpanel").css({
						"margin-right": "0px"
					});
				}
			}, 200);
		}
		if (this.headerList && this.headerList.length != 0) {
			var l = this.headerList.length;
			for (var i = 0; i < l; i++) {
				var header = this.headerList[i];
				header.resize($(header["dom"]).width());
			}
		}
	},
	clear: function(){
		for (var p in this) {
			if (!p || p == 'clear') {
				continue;
			}
			this[p] = null;
			delete this[p];
		}
	}
}


